# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=exiv2
pkgver=0.28.1
pkgrel=0
pkgdesc="Exif and Iptc metadata manipulation library and tools."
url="https://exiv2.org/"
arch="all"
license="GPL-2.0-or-later"
depends_dev="expat-dev zlib-dev"
makedepends="$depends_dev cmake samurai"
checkdepends="gtest-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="https://github.com/Exiv2/exiv2/archive/refs/tags/v$pkgver/exiv2-v$pkgver.tar.gz"

# secfixes:
#   0.28.1-r0:
#     - CVE-2023-44398
#   0.27.5-r0:
#     - CVE-2021-32815
#     - CVE-2021-34334
#     - CVE-2021-34335
#     - CVE-2021-37615
#     - CVE-2021-37616
#     - CVE-2021-37618
#     - CVE-2021-37619
#     - CVE-2021-37620
#     - CVE-2021-37621
#     - CVE-2021-37622
#     - CVE-2021-37623
#   0.27.4-r0:
#     - CVE-2021-29464
#   0.27.3-r2:
#     - CVE-2021-29463
#     - CVE-2021-29470
#     - CVE-2021-29473
#     - CVE-2021-29623
#     - CVE-2021-32617
#   0.27.3-r1:
#     - CVE-2021-3482
#     - CVE-2021-29457
#     - CVE-2021-29458
#     - CVE-2021-31291
#   0.27.2-r6:
#     - CVE-2019-20421
#   0.27.2-r2:
#     - CVE-2019-17402
#   0.27.2-r0:
#     - CVE-2019-13108
#     - CVE-2019-13109
#     - CVE-2019-13110
#     - CVE-2019-13111
#     - CVE-2019-13112
#     - CVE-2019-13113
#     - CVE-2019-13114

prepare() {
	default_prepare

	# -fcf-protection=full is only usable on x86_64 and x86 since those
	# are the arches where Intel's CET Control-Flow Enforcement Technology
	# is available
	# musl doesn't support it at all though, so there is no point to add it
	sed -i 's| -fcf-protection||g' cmake/compilerFlags.cmake
}

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DEXIV2_BUILD_SAMPLES=OFF \
		-DEXIV2_ENABLE_BMFF=ON \
		-DEXIV2_ENABLE_BROTLI=OFF \
		-DEXIV2_ENABLE_INIH=OFF \
		-DEXIV2_BUILD_UNIT_TESTS="$(want_check && echo ON || echo OFF)"
	ninja -C build
}

check() {
	ninja -C build test
}

package() {
	DESTDIR="$pkgdir" ninja -C build install
}

sha512sums="
7b872a3c0cbe343014b1ca4618cecaf6ee8d78dec7ef83accfce95cb8eadc6b52116977a41e1f1be5c6149a47bdd9457fadc08d73708aa2a6ab69795fd3de23b  exiv2-v0.28.1.tar.gz
"
